home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HamCall (April 1991)
/
HAMCALL CD-ROM (Buckmaster)(April 1991).BIN
/
prgming
/
ctutor
/
lottypes.c
< prev
next >
Wrap
Text File
|
1990-10-14
|
2KB
|
72 lines
/* Chapter 4 - Program 3 */
main()
{
int a; /* simple integer type */
long int b; /* long integer type */
short int c; /* short integer type */
unsigned int d; /* unsigned integer type */
char e; /* character type */
float f; /* floating point type */
double g; /* double precision floating point */
a = 1023;
b = 2222;
c = 123;
d = 1234;
e = 'X';
f = 3.14159;
g = 3.1415926535898;
printf("a = %d\n",a); /* decimal output */
printf("a = %o\n",a); /* octal output */
printf("a = %x\n",a); /* hexadecimal output */
printf("b = %ld\n",b); /* decimal long output */
printf("c = %d\n",c); /* decimal short output */
printf("d = %u\n",d); /* unsigned output */
printf("e = %c\n",e); /* character output */
printf("f = %f\n",f); /* floating output */
printf("g = %f\n",g); /* double float output */
printf("\n");
printf("a = %d\n",a); /* simple int output */
printf("a = %7d\n",a); /* use a field width of 7 */
printf("a = %-7d\n",a); /* left justify in field of 7 */
c = 5;
d = 8;
printf("a = %*d\n",c,a); /* use a field width of 5 */
printf("a = %*d\n",d,a); /* use a field width of 8 */
printf("\n");
printf("f = %f\n",f); /* simple float output */
printf("f = %12f\n",f); /* use field width of 12 */
printf("f = %12.3f\n",f); /* use 3 decimal places */
printf("f = %12.5f\n",f); /* use 5 decimal places */
printf("f = %-12.5f\n",f); /* left justify in field */
}
/* Result of execution
a = 1023
a = 1777
a = 3ff
b = 2222
c = 123
d = 1234
e = X
f = 3.141590
g = 3.141593
a = 1023
a = 1023
a = 1023
a = 1023
a = 1023
f = 3.141590
f = 3.141590
f = 3.142
f = 3.14159
f = 3.14159
*/